/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef MOCK_TOPOLOGY_DRIVERS_H
#define MOCK_TOPOLOGY_DRIVERS_H

#include <devmon/driver_abi.h>
#include <mc/engine.h>
#include <mc/log.h>
#include <string>

namespace devmon::test {

class mock_topology_device : public mc::engine::object<mock_topology_device> {
public:
    MC_OBJECT(mock_topology_device, "mock_topology_device", "${object_name}",
              /* no interfaces needed */)

    mock_topology_device() = default;

    bool init(mc::mutable_dict& csr_object, const mc::dict& connector) {
        try {
            from_variant(csr_object, *this);

            if (m_system_id.get_value().is_null() && connector.contains("SystemId")) {
                if (connector.at("SystemId").is_string()) {
                    m_system_id =
                        static_cast<uint8_t>(std::stoul(connector.at("SystemId").as_string()));
                } else {
                    m_system_id = connector.at("SystemId").as<uint8_t>();
                }
            }

            if (m_system_id.get_value().is_null()) {
                elog("Mock device init failed: SystemId is a required property but was not found "
                     "in csr or connector.");
                return false;
            }

        } catch (const std::exception& e) {
            elog("Mock device init failed with exception: ${exception}", ("exception", e.what()));
            return false;
        }

        return true;
    }

    bool start() {
        return true;
    }
    bool stop() {
        return true;
    }

    mc::engine::property<uint8_t> m_system_id;
};

class mock_topology_driver_factory {
public:
    mock_topology_driver_factory()  = default;
    ~mock_topology_driver_factory() = default;
    device_driver_t* create(const std::string& device_name);
};

} // namespace devmon::test

#endif // MOCK_TOPOLOGY_DRIVERS_H